from selenium import webdriver
from .login import login_test
from time import sleep
from ..lib.screenshot_function import screenshot
from selenium.webdriver.chrome.options import Options


def open_browser(browser_name, url):
    driver = None
    chrome_options = Options()
    chrome_options.add_argument("--headless")
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--disable-dev-shm-usage')
    chrome_options.add_argument('--window-size=1920,1080')
    if browser_name == "chrome":
        driver = webdriver.Chrome(chrome_options=chrome_options)
    if browser_name == "ff":
        driver = webdriver.Firefox()
    if browser_name == "ie":
        driver = webdriver.Ie()
    driver.maximize_window()
    driver.implicitly_wait(10)
    driver.get(url)
    return driver


class TestKeys(object):

    def __init__(self, browser_name, url, username, password, new_password):
        self.driver = open_browser(browser_name, url)
        self.username = username
        self.password = password
        self.new_password = new_password

    def webui1(self, list_dicts):
        # 登录
        driver = login_test(self.username, self.driver, self.new_password)
        # 模板管理
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]').click()
        # 模板一览
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]/ul/div/li[1]').click()
        sleep(1)
        returns_list = []
        for dicts in list_dicts:
            if dicts["template_name"] and dicts["os"] and dicts["date_created"] is not None:
                # 筛选条件-模板名称
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[1]/div/div/div/input').send_keys(dicts["template_name"])
                # 系统类型-Linux
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[2]/div/div/div/div[1]/span/span').click()
                sleep(1)
                if dicts["os"] == "Linux":
                    driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
                else:
                    driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/ul/li[2]').click()
                    sleep(1)
                # 创建日期
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[1]').click()
                sleep(1)
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[1]').send_keys(dicts["date_created"][0])
                sleep(1)
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[2]').send_keys(dicts["date_created"][1])
                sleep(1)
                # 查询
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[1]').click()
                sleep(1)
                error_text = driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/footer/div/div/slot/span').text
                print(error_text)
                if error_text == "":
                    error_text = driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/main/div/div[3]/div/span').text
                    print(error_text)
                    # # 重置
                    # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[2]').click()
                    # sleep(1)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            if dicts["template_name"] is not None:
                # 筛选条件-模板名称
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[1]/div/div/div/input').send_keys(dicts["template_name"])
                # 查询
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[1]').click()
                sleep(1)
                error_text = driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/footer/div/div/slot/span').text
                print(error_text)
                if error_text == "":
                    error_text = driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/main/div/div[3]/div/span').text
                    print(error_text)
                    # # 重置
                    # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[2]').click()
                    # sleep(1)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            if dicts["os"] is not None:
                # 系统类型-Linux
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[2]/div/div/div/div[1]/span/span').click()
                sleep(1)
                if dicts["os"] == "Linux":
                    driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
                else:
                    driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/ul/li[2]').click()
                    sleep(1)
                # 查询
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[1]').click()
                sleep(1)
                error_text = driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/footer/div/div/slot/span').text
                print(error_text)
                if error_text == "":
                    error_text = driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/main/div/div[3]/div/span').text
                    print(error_text)
                # 重置
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            # # 系统类型-windows
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[2]/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[1]/ul/li[2]').click()
            # sleep(1)
            # # 查询
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[1]').click()
            # sleep(1)
            # # 重置
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[2]').click()
            # sleep(1)
            if dicts["date_created"] is not None:
                # 创建日期
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[1]').click()
                sleep(1)
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[1]').send_keys(dicts["date_created"][0])
                sleep(1)
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[2]').send_keys(dicts["date_created"][1])
                sleep(1)
                # 查询
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[1]').click()
                sleep(1)
                error_text = driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[2]/footer/div/div/slot/span').text
                print(error_text)
                if error_text == "":
                    error_text = driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/main/div/div[3]/div/span').text
                    print(error_text)
                # # 重置
                # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[2]').click()
                # sleep(3)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
        print(returns_list)
        return returns_list

    def webui2(self, list_dicts):
        # 登录
        driver = login_test(self.username, self.driver, self.new_password)
        # 模板管理
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]').click()
        # 模板一览
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]/ul/div/li[1]').click()
        sleep(1)
        # 模板新增
        driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/header/div[2]/button[1]').click()
        sleep(1)
        returns_list = []
        for dicts in list_dicts:
            if dicts["template_name"] is not None:
                # 模板创建-模板名称
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/form/div[1]/div/div/div/div/input').send_keys(dicts["template_name"])
            if dicts["os"] == "Windows":
                # 模板系统
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/form/div[2]/div/div/div/label[2]/span[1]').click()
            # 描述
            driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/form/div[4]/div/div/div/div/textarea').send_keys("模板描述测试")
            # 下一步
            driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[2]/button').click()
            sleep(1)
            if dicts["template_name"] is None:
                error_text = driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/form/div[1]/div/div/div/div[2]').text
                print(error_text)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            if len(dicts["template_name"]) > 32:
                error_text = driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/form/div[1]/div/div/div/div[2]').text
                print(error_text)
                returns_list.append(error_text)
                driver.refresh()
                sleep(2)
                continue
            # 模板配置-筛选条件-来源
            driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/main/div/main/form/div/div/div/div/div/div[1]/span/span').click()
            sleep(1)
            driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/ul/li[1]').click()
            # 查询
            driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/main/div/main/form/div/button[1]').click()
            sleep(2)
            # 重置
            driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/main/div/main/form/div/button[2]').click()
            sleep(2)
            # 模板一览列表-操作系统
            # 全选
            driver.find_element_by_xpath('//*[@id="pane-1"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
            sleep(1)
            # 模板一览列表-数据库
            driver.find_element_by_xpath('//*[@id="tab-2"]').click()
            sleep(1)
            # 全选
            driver.find_element_by_xpath('//*[@id="pane-2"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
            sleep(1)
            # 模板一览列表-中间件
            driver.find_element_by_xpath('//*[@id="tab-3"]').click()
            sleep(1)
            # 全选
            driver.find_element_by_xpath('//*[@id="pane-3"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
            sleep(1)
            # 模板一览列表-安全设备
            driver.find_element_by_xpath('//*[@id="tab-4"]').click()
            sleep(1)
            # 全选
            driver.find_element_by_xpath('//*[@id="pane-4"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
            sleep(1)
            # 模板一览列表-网络设备
            driver.find_element_by_xpath('//*[@id="tab-5"]').click()
            sleep(1)
            # 全选
            driver.find_element_by_xpath('//*[@id="pane-5"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
            sleep(1)
            # 下一步
            driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[3]/button[2]').click()
            sleep(2)
            # 保存
            driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[3]/button[2]').click()
            sleep(4)
            # # 模板新增
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/header/div[2]/button[1]').click()
            # sleep(1)
            # # 模板创建-模板名称
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/form/div[1]/div/div/div/div/input').send_keys("模板名称测试2")
            # # 模板系统
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/form/div[2]/div/div/div/label[2]/span[1]').click()
            # # 描述
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/form/div[4]/div/div/div/div/textarea').send_keys("模板描述测试2")
            # # 下一步
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[2]/button').click()
            # # 模板配置-筛选条件-来源
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/main/div/main/form/div/div/div/div/div/div[1]/span/span').click()
            # sleep(1)
            # driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/ul/li[1]').click()
            # # 查询
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/main/div/main/form/div/button[1]').click()
            # sleep(2)
            # # 重置
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/main/div/main/form/div/button[2]').click()
            # sleep(3)
            # # 模板一览列表-操作系统
            # # 全选
            # driver.find_element_by_xpath('//*[@id="pane-1"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
            # sleep(1)
            # # 模板一览列表-数据库
            # driver.find_element_by_xpath('//*[@id="tab-2"]').click()
            # sleep(1)
            # # 全选
            # driver.find_element_by_xpath('//*[@id="pane-2"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
            # sleep(1)
            # # 模板一览列表-中间件
            # driver.find_element_by_xpath('//*[@id="tab-3"]').click()
            # sleep(1)
            # # 全选
            # driver.find_element_by_xpath('//*[@id="pane-3"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
            # sleep(1)
            # # 模板一览列表-安全设备
            # driver.find_element_by_xpath('//*[@id="tab-4"]').click()
            # sleep(1)
            # # 全选
            # driver.find_element_by_xpath('//*[@id="pane-4"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
            # sleep(1)
            # # 模板一览列表-网络设备
            # driver.find_element_by_xpath('//*[@id="tab-5"]').click()
            # sleep(1)
            # # 全选
            # driver.find_element_by_xpath('//*[@id="pane-5"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
            # sleep(1)
            # # 下一步
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[3]/button[2]').click()
            # sleep(2)
            # # 保存
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[3]/button[2]').click()
            # sleep(3)
            # 模板名称
            driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[1]/div/div/div/input').send_keys(dicts["template_name"])
            # 查询
            driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[1]').click()
            sleep(2)
            returns_list.append("新增成功")
            driver.refresh()
            sleep(2)
            # 模板新增
            driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/header/div[2]/button[1]').click()
            sleep(1)
            continue
            # # 删除
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/main/div/div[3]/table/tbody/tr[1]/td[6]/div/button[2]').click()
            # sleep(1)
            # # 确定
            # driver.find_element_by_xpath('/html/body/div[6]/div/div[3]/button[2]').click()
            # sleep(2)
            # # 选中第一个
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/main/div/div[3]/table/tbody/tr[1]/td[1]/div/label/span').click()
            # # 选中第二个
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/main/div/div[3]/table/tbody/tr[2]/td[1]/div/label/span').click()
            # sleep(1)
            # # 批量删除
            # driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/header/div[2]/button[2]').click()
            # sleep(1)
            # # 确定
            # driver.find_element_by_xpath('/html/body/div[6]/div/div[3]/button[2]').click()
            # sleep(3)
        print(returns_list)
        return returns_list

    def webui3(self, list_dicts):
        # 登录
        driver = login_test(self.username, self.driver, self.new_password)
        # 模板管理
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]').click()
        # 模板一览
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]/ul/div/li[1]').click()
        sleep(1)
        returns_list = []
        for dicts in list_dicts:
            if dicts["template_name"] and dicts["os"] and dicts["date_created"] is not None:
                # 筛选条件-模板名称
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[1]/div/div/div/input').send_keys(dicts["template_name"])
                # 系统类型-Linux
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[2]/div/div/div/div[1]/span/span').click()
                sleep(1)
                if dicts["os"] == "Linux":
                    driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
                else:
                    driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/ul/li[2]').click()
                    sleep(1)
                # 创建日期
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[1]').click()
                sleep(1)
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[1]').send_keys(dicts["date_created"][0])
                sleep(1)
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[2]').send_keys(dicts["date_created"][1])
                sleep(1)
                # 查询
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[1]').click()
                sleep(2)
                # 编辑
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/main/div/div[3]/table/tbody/tr/td[6]/div/button[1]').click()
                sleep(1)
                # 模板名称
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/form/div[1]/div/div/div/div/input').clear()
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/form/div[1]/div/div/div/div/input').send_keys(dicts["template_name_2"])
                sleep(1)
                if dicts["os_2"] == "Windows":
                    # 模板系统
                    driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/form/div[2]/div/div/div/label[2]/span[1]').click()
                # 描述
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/form/div[4]/div/div/div/div/textarea').send_keys("模板描述测试PUT")
                # 下一步
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[2]/button').click()
                sleep(1)
                # 模板配置-筛选条件-来源
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/main/div/main/form/div/div/div/div/div/div[1]/span/span').click()
                sleep(1)
                driver.find_element_by_xpath('/html/body/div[6]/div[1]/div[1]/ul/li[1]').click()
                # 查询
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/main/div/main/form/div/button[1]').click()
                sleep(2)
                # 重置
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[1]/main/div/main/form/div/button[2]').click()
                sleep(2)
                # 模板一览列表-操作系统
                # 全选
                driver.find_element_by_xpath(
                    '//*[@id="pane-1"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
                sleep(1)
                # 模板一览列表-数据库
                driver.find_element_by_xpath('//*[@id="tab-2"]').click()
                sleep(1)
                # 全选
                driver.find_element_by_xpath(
                    '//*[@id="pane-2"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
                sleep(1)
                # 模板一览列表-中间件
                driver.find_element_by_xpath('//*[@id="tab-3"]').click()
                sleep(1)
                # 全选
                driver.find_element_by_xpath(
                    '//*[@id="pane-3"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
                sleep(1)
                # 模板一览列表-安全设备
                driver.find_element_by_xpath('//*[@id="tab-4"]').click()
                sleep(1)
                # 全选
                driver.find_element_by_xpath(
                    '//*[@id="pane-4"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
                sleep(1)
                # 模板一览列表-网络设备
                driver.find_element_by_xpath('//*[@id="tab-5"]').click()
                sleep(1)
                # 全选
                driver.find_element_by_xpath(
                    '//*[@id="pane-5"]/div/main/div/div[2]/table/thead/tr/th[1]/div/label/span').click()
                sleep(1)
                # 下一步
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[3]/button[2]').click()
                sleep(2)
                # 保存
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div/main/div[2]/div[3]/button[2]').click()
                sleep(4)
                # 模板名称
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[1]/div/div/div/input').send_keys(dicts["template_name_2"])
                sleep(1)
                # 系统类型
                # 系统类型-Linux
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[2]/div/div/div/div[1]/span/span').click()
                sleep(1)
                if dicts["os_2"] == "Linux":
                    driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
                else:
                    driver.find_element_by_xpath('/html/body/div[6]/div[1]/div[1]/ul/li[2]').click()
                    sleep(1)
                # 创建日期
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[1]').click()
                sleep(1)
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[1]').send_keys(
                    dicts["date_created"][0])
                sleep(1)
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[2]').send_keys(
                    dicts["date_created"][1])
                sleep(1)
                # 查询
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[1]').click()
                sleep(2)
                error_text = driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/footer/div/div/slot/span').text
                print(error_text)
                if error_text == "共 1 条":
                    returns_list.append("编辑成功")
                else:
                    returns_list.append("编辑失败")
                # 重置
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[2]').click()
                sleep(1)
                continue
        print(returns_list)
        return returns_list

    def webui4(self, list_dicts):
        # 登录
        driver = login_test(self.username, self.driver, self.new_password)
        # 模板管理
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]').click()
        # 模板一览
        driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/div/li[4]/ul/div/li[1]').click()
        sleep(1)
        returns_list = []
        for dicts in list_dicts:
            if dicts["template_name"] and dicts["os"] and dicts["date_created"] is not None:
                # 筛选条件-模板名称
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[1]/div/div/div/input').send_keys(dicts["template_name"])
                # 系统类型-Linux
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[2]/div/div/div/div[1]/span/span').click()
                sleep(1)
                if dicts["os"] == "Windows":
                    driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[1]/ul/li[2]').click()
                    sleep(1)
                else:
                    driver.find_element_by_xpath('/html/body/div[7]/div[1]/div[1]/ul/li[2]').click()
                    sleep(1)
                # 创建日期
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[1]').click()
                sleep(1)
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[1]').send_keys(dicts["date_created"][0])
                sleep(1)
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[2]').send_keys(dicts["date_created"][1])
                sleep(1)
                # 查询
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[1]').click()
                sleep(2)
                # 删除
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/main/div/div[3]/table/tbody/tr/td[6]/div/button[2]').click()
                sleep(1)
                # 确定
                driver.find_element_by_xpath('/html/body/div[8]/div/div[3]/button[2]').click()
                # 重置
                driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[2]').click()
                sleep(2)
                # 筛选条件-模板名称
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[1]/div/div/div/input').send_keys(
                    dicts["template_name"])
                # 系统类型-Linux
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[2]/div/div/div/div[1]/span/span').click()
                sleep(1)
                if dicts["os"] == "Linux":
                    driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[1]/ul/li[1]').click()
                    sleep(1)
                else:
                    driver.find_element_by_xpath('/html/body/div[7]/div[1]/div[1]/ul/li[2]').click()
                    sleep(1)
                # 创建日期
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[1]').click()
                sleep(1)
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[1]').send_keys(
                    dicts["date_created"][0])
                sleep(1)
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[1]/div[3]/div/div/div/input[2]').send_keys(
                    dicts["date_created"][1])
                sleep(1)
                # 查询
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[1]').click()
                sleep(2)
                error_text = driver.find_element_by_xpath('//*[@id="app"]/section/section/main/section/div/div[2]/main/div/div[3]/div/span').text
                print(error_text)
                if error_text == "暂无数据":
                    returns_list.append("删除成功")
                else:
                    returns_list.append("删除失败")
                # 重置
                driver.find_element_by_xpath(
                    '//*[@id="app"]/section/section/main/section/div/div[1]/main/div/main/form/div[2]/button[2]').click()
                continue
        print(returns_list)
        return returns_list

    def quit(self):
        """
        浏览器退出
        :return:
        """
        self.driver.quit()